package com.lanchetech.user.controller;

import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.MiniappService;
import com.lanchetech.user.service.WechatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Api(value = "微信功能", tags = "微信功能")
@RequestMapping("/api/wechat")
@RestController
public class WechatController {

    @Autowired
    WechatService wechatService;

    @Autowired
    MiniappService miniappService;

    @ApiOperation("获取直播间分页")
    @PostMapping("/getLiveRoomList")
    public ResultData<WxMaLiveResult> getLiveRoomList(@RequestBody PageReq req) {
        req.setPageNo(req.getPageNo() - 1);
        return miniappService.getLiveInfo(req.getPageNo(), req.getPageSize());
    }

    @ApiOperation("生成小程序直播间的分享图片")
    @GetMapping("/createMiniLiveQrcode")
    public ResultData<String> createMiniLiveQrcode(@AuthenticationPrincipal User user) {
        return miniappService.createMiniLiveQrcode(user);
    }

}
